package org.example.login2;

import java.util.ArrayList;
import java.util.List;

public class InMemoryStudentDatabase {
    private static List<Student> studentList = new ArrayList<>();

    public static List<Student> getStudentList() {
        return studentList;
    }

    public static void addStudent(Student student) throws DuplicateStudentIdException {
        for (Student existingStudent : studentList) {
            if (existingStudent.getId().equals(student.getId())) {
                throw new DuplicateStudentIdException("学号 " + student.getId() + " 已存在！");
            }
        }
        studentList.add(student);
    }

    public static void removeStudent(String id) {
        studentList.removeIf(student -> student.getId().equals(id));
    }

}

